﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.ships.cruise {
    import Classes.*;
    import Classes.sim.*;
    import Classes.actions.*;
    import Engine.*;

    public class CruisePeepActionSelection extends PeepActionSelection {

        protected var m_visited:Boolean;
        protected var m_dock:MapResource;

        public function CruisePeepActionSelection(_arg1:Peep, _arg2:MapResource){
            super(_arg1);
            this.m_dock = _arg2;
            this.m_visited = false;
        }
        override public function getNextActions():Array{
            var _local1:SelectionResult = SelectionResult.FAIL;
            m_peep.beforeDecision();
            if (this.m_visited){
                _local1 = this.goBackToShip();
            } else {
                _local1 = goToMerchant();
                if (_local1 != SelectionResult.FAIL){
                    this.m_visited = true;
                };
            };
            if (_local1 == SelectionResult.FAIL){
                _local1 = this.wander();
            };
            return (_local1.actions);
        }
        protected function goBackToShip():SelectionResult{
            var _local5:Array;
            var _local6:RoadGraph;
            var _local7:MapResource;
            var _local1:Array = [];
            if (this.m_dock == null){
                return (SelectionResult.FAIL);
            };
            var _local2:MapResource;
            var _local3:MapResource = Global.world.citySim.roadManager.findClosestWalkableTile(m_peep.getPosition());
            var _local4:* = Global.world.citySim.roadManager.findPath(_local3, this.m_dock, RoadManager.PATH_TO_FRONT_ENTRANCE);
            if (_local4 == null){
                _local5 = Global.world.citySim.roadManager.findAllGraphsForWalkableTile(_local3);
                for each (_local6 in _local5) {
                    _local7 = Global.world.citySim.roadManager.findClosestWalkableTileInGraph(this.m_dock.getPosition(), _local6);
                    if (_local7 != null){
                        _local2 = _local7;
                        break;
                    };
                };
            };
            _local1 = [new ActionEnableFreedom(m_peep, false)];
            if (_local2 == null){
                _local1.push(new ActionNavigate(m_peep, this.m_dock, null).setPathType(RoadManager.PATH_FULL).setTeleportOnFailure(true));
            } else {
                _local1.push(new ActionNavigate(m_peep, _local2, null).setPathType(RoadManager.PATH_FULL));
                _local1.push(new ActionNavigateBeeline(m_peep, CruiseShipUtil.getRoadsideDockEntrance(this.m_dock)));
            };
            _local1.push(new ActionDie(m_peep));
            return (new SelectionResult(this.m_dock, _local1));
        }
        protected function wander():SelectionResult{
            var _local1:Number = Global.gameSettings.getNumber("npcWanderTimeSec", 15);
            var _local2:Number = Global.gameSettings.getNumber("npcWanderTimePlusMinus", 5);
            var _local3:Number = MathUtil.random((_local1 + _local2), (_local1 - _local2));
            return (new SelectionResult(null, [new ActionEnableFreedom(m_peep, false), new ActionNavigateRandom(m_peep).setTimeout(_local3), new ActionEnableFreedom(m_peep, true)]));
        }

    }
}//package Modules.ships.cruise 
